Faster JSON parsing
authorMattias Engdegård <mattiase@acm.org>
Sun, 31 Mar 2024 13:00:00 +0000 (15:00 +0200)
committerMattias Engdegård <mattiase@acm.org>
Mon, 1 Apr 2024 08:41:46 +0000 (10:41 +0200)
commit734bd005aa0fa955cf1a46d3a60a4d6ef5e7e3d1
tree28e48c30e5916247065e8e66d9a80d9991ec1c2b
parentf178a6d8006f1e8afe06bb71d0a413622d73f131
Faster JSON parsing

Speed up JSON parsing substantially by only UTF-8-parsing string
literals and only exactly once.  Previously, json-parse-string always
first parsed the entire input and copied it to a new string, and then
validated each string literal twice.

We no longer create an extra new string when interning an alist key,
nor do we garble plist keys with Unicode characters.

* src/lread.c (intern_c_multibyte): New.
* src/json.c (json_encode): Remove.
(utf8_error): New.
(json_parse_string): Faster and more careful UTF-8 decoding.
Create and return a new multibyte string or symbol without extra
decoding.  All callers adapted.
(Fjson_parse_string): Skip expensive input pre-decoding.
* test/src/json-tests.el (json-parse-string/object-unicode-keys)
(json-parse-string/short): New.
(json-parse-string/string, json-parse-string/invalid-unicode):
Adapt tests.
* etc/NEWS: Mentioned change in errors.
etc/NEWS
src/json.c
src/lisp.h
src/lread.c
test/src/json-tests.el